import { json } from "@remix-run/node";
import { authenticate } from "../shopify.server";
import type { LoaderFunctionArgs } from "@remix-run/node";

export const loader = async ({ request }: LoaderFunctionArgs) => {
  try {
    const { session } = await authenticate.admin(request);
    
    if (!session) {
      console.error('Session not found');
      return json({
        error: '未找到有效的会话',
        success: false
      }, { status: 401 });
    }

    return json({
      access_token: session.accessToken,
      shop: session.shop,
      success: true
    });
  } catch (error: any) {
    console.error('获取 Shopify 信息失败:', error);
    return json({
      error: error.message || '获取 Shopify 信息失败',
      success: false
    }, { status: 500 });
  }
}; 